import hashlib


def setPassword(password):
    md5 = hashlib.md5()
    md5.update(password.encode())
    result = md5.hexdigest()
    return result


from alipay import AliPay


def myPay(order_id, money):
    alipay_public_key_string = """-----BEGIN PUBLIC KEY-----
    MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAljwpy8woneHkQYY+f58votx/f3lQ8lmMctjkMpsfsrBw23F9Xkq3Pk5yp2p8W+FxcE8gAzmd479r4up9x2pAt29IhTyY87Tju0Wp5oDk5VwtzbMtX81QSy+LTQBbCAb7CidQupflg3q2KR1Liyigd5ahTqUqcGiBHyT4bxH1H5+Pt80DH+SrvzGQEiIkrLJ6deZr22vmzFbjk3pysvngQBMVOgPT74r8CNKa0bTHvpHrTmuyl4eGuUYc07NPq0ltFozzNRJuBePw7PZk0w8D7kWimIMGia7ssUxxzuj/Bad+jQeLiRKSnrE4BCgKB4/Rs849HN9ubUDat1UpKMKF+QIDAQAB
    -----END PUBLIC KEY-----"""

    app_private_key_string = """-----BEGIN RSA PRIVATE KEY-----
    MIIEowIBAAKCAQEAp8aYICwO78coQBD7hneCBK0c+If4L28G4Ppo1XBxg9rZmYMmDuOoZEwKe238umpY7042/7/yAItWkQm9ypHJXKqBD+xKYZFx4vQRk44/x5qa3KiDpIrQ/7OjL1HfPZ4XNr43/9aiCO34gYblwJX3axLE3FI8XoVt5lSSMqq1QEngtbpYt6L6QRLE6N0YBW5TQwRpv5ZnP+zn5nOBsFavQfYsfellvD3WISfCGoP7AYvc3t7qJEsndMYiaddQyBql+KdG9c0xcT/PsNE8Rr5EXX+bhvhRsFfxzvAekIDnBA3fMrXMMDtIoOmzwOcAIZlcQYC2rGzacTmzQWF8VcrdvQIDAQABAoIBAHGKDSMgjc8oyQ1qML2UHLILcSKj6Yo4KcCQ1ecznC5uKXog7d1/pVKSvzk+epyxIZR5KvEytZQ2t5OZsw3mUQ3b+VGMR931bsv2/foMdw8eipSvmb79jmis6c85KclqNi1+1yjU2H0Qhm8pmkwVcQXOAtlS8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EY-----"""

    # 实例化阿里支付功能
    alipay = AliPay(
        appid='202011062941',
        app_notify_url=None,
        app_private_key_string=app_private_key_string,
        alipay_public_key_string=alipay_public_key_string,
        sign_type="RSA2"
    )

    # 发起支付，网页支付
    order_string = alipay.api_alipay_trade_page_pay(
        out_trade_no=order_id,  # 订单号，自定义，但是不可以重复
        total_amount=str(money),  # 支付的金额，必须是字符串
        subject="洗jio",  # 消费的方式
        return_url='http://127.0.0.1:8000/buyer/pay_success/',  # 返回结果地址
        notify_url='http://127.0.0.1:8000/buyer/pay_success/',  # 支付通知的地址
    )
    result = "https://openapi.alipaydev.com/gateway.do?"+order_string
    return result









